import axios from '../../util/http'

const user = {
  state:{
    opendId:sessionStorage.getItem('openId'),

  },
  mutations:{
    SET_OPENID:(state,data)=>{
      state.opendId = data
    }
  },
  actions:{
    queryGetOpenId:({commit, rootState},code)=>{
      return new Promise((resolve,reject)=>{
        axios.post(rootState.getOpenId,{code:code}).then(res=>{
          console.log(`queryGetOpenId:${res.data.openId}`)
          let openId = res.data.openId
          sessionStorage.setItem('openId',openId)
          resolve(openId)
          commit('SET_OPENID',openId)
        }).catch(e=>{
          reject(e)
        })
      })

    }
  }
}

export default user
